/*
	2018-7-1 miaov

	npm init -y 初始化 项目， -y 取默认值

	webpack 会自动转换 import 和 export
*/

const path = require('path');
const cleanWebpackPlugin = require('clean-webpack-plugin');
const htmlWebpackPlugin = require('html-webpack-plugin');

function resolve( ...dirs ){
	if( dirs.length == 1 ){
		return path.resolve( __dirname, dirs[0] );
	}else{
		return dirs.map( (item) => path.resolve( __dirname, item ))
	}
}

module.exports = {
	entry : resolve('6/src/app.js'),
	output : {
		path : resolve('6/dist'), // 打包后的文件路径
		filename : 'js/[name].js',
	},
	plugins : [
		new cleanWebpackPlugin([resolve('6/dist/')]),
		new htmlWebpackPlugin({
			template : resolve('6/index.html'),
			filename : 'index.html',
			title : 'react webpack',
			inject : 'body',
		})
	],
	module : {
		rules : [{
				test : /\.js$/,
				use : [{
						loader : 'babel-loader',
						options : {
							presets : ['react']
						} 
					}
				]
			},{
				test : /\.css$/,
				use : [{
					loader : 'css-loader'
				}]
			}
		],
	},
	// 配置服务器
	devServer : {
		open : true,
		port : 9000
	}
}